
#include "imageViewer.h"

#include <QtGui/QPalette>
#include <QtGui/QColor>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtCore/Qt>

#include <QtGui/QImage>
#include <QtGui/QPainter>
#include <QtCore/QRect>
#include <QtCore/QPoint>

/*----------------------------------------------------------------------------*/

ImageViewer::ImageViewer( QWidget* _parent  )
	: QWidget( _parent )
	, m_image( NULL )
{	
	QPalette palette;
	palette.setBrush( this->backgroundRole(), QBrush( QColor( Qt::transparent ) ) );
	this->setPalette( palette );
	this->setAutoFillBackground( true );

	this->setMouseTracking( true );
}


/*----------------------------------------------------------------------------*/


ImageViewer::~ImageViewer()
{
	if( m_image )
		delete m_image;
}


/*----------------------------------------------------------------------------*/


void ImageViewer::paintEvent( QPaintEvent* )
{
	QPainter painter( this );
	if( m_image )
	{
		QImage scaled_img = m_image->scaled( m_image->width() * 5, m_image->height() * 5 );
		QPoint coord = this->frameGeometry().center() - scaled_img.rect().center();
		painter.drawImage( coord, scaled_img );
	}
}


/*----------------------------------------------------------------------------*/


void ImageViewer::SetImage( QImage* _image )
{
	if( m_image )
		delete m_image;
	m_image = _image;
	this->repaint();
}	


/*----------------------------------------------------------------------------*/


void ImageViewer::CloseImage()
{
	if( m_image )
		delete m_image;
	m_image = NULL;
	this->repaint();
}


/*----------------------------------------------------------------------------*/


QImage& ImageViewer::GetImage()
{
	return *m_image;
}

/*----------------------------------------------------------------------------*/
